<script setup>
import InputEditer from '../components/InputEditer.vue'
import InputEditerArrdev from '../components/InputEditerArrDev.vue'
import { ref, onMounted, nextTick } from 'vue'
import { dataProcessing_devicedriver } from '../js/dataPro_deviceDriver.js'
import { _getData } from '/src/api/parameterConfiguration/getData.js'
import { mainStore } from '/src/store/mainStore.js'

const store = mainStore()

let data = ref(null)

const getList = async () => {
  data.value = null
  const res = await _getData(store.cutArgPage)

  if (res?.data?.code != 200) return ElMessage.error('获取数据失败')
  data.value = dataProcessing_devicedriver(res.data.data, store.cutArgPage)
}

const handleTitleClick = async (value) => {
  // 清空当前的所有东西
  store.saveAllData = []
  store.cutArgPage = value
  await getList()
}

getList()
let height = ref('0px')
onMounted(() => {
  nextTick(() => {
    const h = document.querySelector('.dev-container').getBoundingClientRect().height
    height.value = h - 100 + 'px'
  })
})
</script>

<template>
  <div class="dev-container">
    <!-- 主要的参数 -->
    <h3>设备驱动</h3>
    <!-- 主要的参数 -->
    <div class="title">
      <div @click="handleTitleClick('device-driver-rsu')" :class="store.cutArgPage == 'device-driver-rsu' ? 'selecdCss' : ''">rsu驱动</div>
      <div @click="handleTitleClick('device-driver-radar')" :class="store.cutArgPage == 'device-driver-radar' ? 'selecdCss' : ''">毫米波驱动</div>
      <div @click="handleTitleClick('device-driver-traffic-light')" :class="store.cutArgPage == 'device-driver-traffic-light' ? 'selecdCss' : ''">信号机驱动</div>
      <div @click="handleTitleClick('device-driver-cloud')" :class="store.cutArgPage == 'device-driver-cloud' ? 'selecdCss' : ''">路云驱动</div>
    </div>
    <!-- 头部的输入-->
    <div class="show-main" :style="{ height }">
      <div v-for="item in data?.data_main">
        <InputEditer v-if="!item.arr" :data="item" :width="200" />
        <InputEditerArrdev v-else :data="item" />
      </div>
    </div>
  </div>
</template>

<style lang="less" scoped>
.dev-container {
  width: 100%;
  height: 100%;
  font-size: 14px;
  padding: 0 6px 0 20px;
  display: flex;
  flex-direction: column;
}

.show-main {
  width: 100%;
  margin-top: 10px;
  display: flex;
  flex-direction: column;
  padding: 20px 40px;
  // border-bottom: 1px solid #ccc;
  overflow-y: auto;
  > div {
    width: 700px;
    margin-right: 80px;
    margin-bottom: 20px;
  }
}

.title {
  width: 100%;
  margin-top: 10px;
  display: flex;
  align-items: center;
  > div {
    width: 80px;
    margin-right: 10px;
    height: 22px;
    background-color: #ccc;
    line-height: 22px;
    border-radius: 2px;
    cursor: pointer;
    text-align: center;
  }
}

.selecdCss {
  color: white;
  background-color: #4095e5 !important;
}

h3 {
  width: 100%;
  margin-top: 20px;
}
</style>
